package com.robotic.sensor.domain;

import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.robotic.common.annotation.Excel;
import com.robotic.common.core.domain.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

/**
 * 区域标准配置对象 region_standard
 * 
 * @author robotic
 * @date 2024-01-20
 */
@TableName("region_standard")
public class RegionStandard extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 主键ID */
    @TableId(type = IdType.AUTO)
    private Long id;

    /** 区域代码 */
    @Excel(name = "区域代码")
    private String regionCode;

    /** 传感器类型(temperature/gas) */
    @Excel(name = "传感器类型", readConverterExp = "temperature=温度,gas=气体")
    private String sensorType;

    /** 正常值下限 */
    @Excel(name = "正常值下限")
    private BigDecimal normalMin;

    /** 正常值上限 */
    @Excel(name = "正常值上限")
    private BigDecimal normalMax;

    /** 警告值下限 */
    @Excel(name = "警告值下限")
    private BigDecimal warningMin;

    /** 警告值上限 */
    @Excel(name = "警告值上限")
    private BigDecimal warningMax;

    /** 危险值下限 */
    @Excel(name = "危险值下限")
    private BigDecimal dangerMin;

    /** 危险值上限 */
    @Excel(name = "危险值上限")
    private BigDecimal dangerMax;

    /** 单位(℃/ppm等) */
    @Excel(name = "单位")
    private String unit;

    /** 描述信息 */
    @Excel(name = "描述信息")
    private String description;

    /** 状态(1启用 0禁用) */
    @Excel(name = "状态", readConverterExp = "1=启用,0=禁用")
    private String status;

    public void setId(Long id) 
    {
        this.id = id;
    }

    public Long getId() 
    {
        return id;
    }
    public void setRegionCode(String regionCode) 
    {
        this.regionCode = regionCode;
    }

    public String getRegionCode() 
    {
        return regionCode;
    }
    public void setSensorType(String sensorType) 
    {
        this.sensorType = sensorType;
    }

    public String getSensorType() 
    {
        return sensorType;
    }
    public void setNormalMin(BigDecimal normalMin) 
    {
        this.normalMin = normalMin;
    }

    public BigDecimal getNormalMin() 
    {
        return normalMin;
    }
    public void setNormalMax(BigDecimal normalMax) 
    {
        this.normalMax = normalMax;
    }

    public BigDecimal getNormalMax() 
    {
        return normalMax;
    }
    public void setWarningMin(BigDecimal warningMin) 
    {
        this.warningMin = warningMin;
    }

    public BigDecimal getWarningMin() 
    {
        return warningMin;
    }
    public void setWarningMax(BigDecimal warningMax) 
    {
        this.warningMax = warningMax;
    }

    public BigDecimal getWarningMax() 
    {
        return warningMax;
    }
    public void setDangerMin(BigDecimal dangerMin) 
    {
        this.dangerMin = dangerMin;
    }

    public BigDecimal getDangerMin() 
    {
        return dangerMin;
    }
    public void setDangerMax(BigDecimal dangerMax) 
    {
        this.dangerMax = dangerMax;
    }

    public BigDecimal getDangerMax() 
    {
        return dangerMax;
    }
    public void setUnit(String unit) 
    {
        this.unit = unit;
    }

    public String getUnit() 
    {
        return unit;
    }
    public void setDescription(String description) 
    {
        this.description = description;
    }

    public String getDescription() 
    {
        return description;
    }
    public void setStatus(String status) 
    {
        this.status = status;
    }

    public String getStatus() 
    {
        return status;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("regionCode", getRegionCode())
            .append("sensorType", getSensorType())
            .append("normalMin", getNormalMin())
            .append("normalMax", getNormalMax())
            .append("warningMin", getWarningMin())
            .append("warningMax", getWarningMax())
            .append("dangerMin", getDangerMin())
            .append("dangerMax", getDangerMax())
            .append("unit", getUnit())
            .append("description", getDescription())
            .append("status", getStatus())
            .append("createBy", getCreateBy())
            .append("createTime", getCreateTime())
            .append("updateBy", getUpdateBy())
            .append("updateTime", getUpdateTime())
            .append("remark", getRemark())
            .toString();
    }

    /**
     * 判断传感器数据是否在正常范围内
     * @param value 传感器数据值
     * @return true-正常，false-异常
     */
    public boolean isNormal(BigDecimal value) {
        if (value == null || normalMin == null || normalMax == null) {
            return false;
        }
        return value.compareTo(normalMin) >= 0 && value.compareTo(normalMax) <= 0;
    }

    /**
     * 判断传感器数据是否在警告范围内
     * @param value 传感器数据值
     * @return true-警告，false-非警告
     */
    public boolean isWarning(BigDecimal value) {
        if (value == null || warningMin == null || warningMax == null) {
            return false;
        }
        return (value.compareTo(warningMin) >= 0 && value.compareTo(normalMin) < 0) ||
               (value.compareTo(normalMax) > 0 && value.compareTo(warningMax) <= 0);
    }

    /**
     * 判断传感器数据是否在危险范围内
     * @param value 传感器数据值
     * @return true-危险，false-非危险
     */
    public boolean isDanger(BigDecimal value) {
        if (value == null || dangerMin == null || dangerMax == null) {
            return false;
        }
        return value.compareTo(dangerMin) < 0 || value.compareTo(dangerMax) > 0;
    }

    /**
     * 获取传感器数据的检测状态
     * @param value 传感器数据值
     * @return normal/warning/danger
     */
    public String getDetectStatus(BigDecimal value) {
        if (isDanger(value)) {
            return "danger";
        } else if (isWarning(value)) {
            return "warning";
        } else if (isNormal(value)) {
            return "normal";
        } else {
            return "unknown";
        }
    }
}